
package com.training.oo.object;

public class Room implements Cloneable{
	private TV tv;

	public TV getTv() {
		return tv;
	}

	public void setTv(TV tv) {
		this.tv = tv;
	}

	@Override
	public String toString() {
		return "Room [tv=" + tv + "]";
	}
	
	@Override
	public Object clone() throws CloneNotSupportedException {
		TV tx = new TV();
		tx.setBrand(this.tv.getBrand());
		
		Room r = new Room();
		r.setTv(tx);
		return r;
	}
	
	public static void main(String[] args) throws CloneNotSupportedException  {
		TV tv = new TV();
		tv.setBrand("TCL");
		
		Room r1 = new Room();
		r1.setTv(tv);
		
		System.out.println("r1:"+r1);
		
		Room r2 = (Room)r1.clone();
		
		tv.setBrand("小米");	
		
		System.out.println("r1:"+r1);		
		System.out.println("r2:"+r2);
	}
}
